package com.datatest.ex;

import com.datatest.beans.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.io.FileNotFoundException;
import java.io.IOException;

@RestControllerAdvice
public class GlobalExceptionHander  {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHander.class);

    /**
     * 处理自定义异常
     * @return
     */
    @ExceptionHandler(value = BusinessException.class)
    public ResultEntity bizExceptionHandler(BusinessException e){
        log.error(e.getMessage(),e);
        return ResultEntity.defineError(e);
    }



    @ExceptionHandler(value = NullPointerException.class)
    public ResultEntity otherError(NullPointerException e){
        log.error(e.getMessage(),e);
        return ResultEntity.fileNotError(e);
    }
}
